// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { Utils } from "../CCFramework/util/Utils";

const { ccclass, property, executeInEditMode } = cc._decorator;

@ccclass
@executeInEditMode
export default class NewClass extends cc.Component {
    @property(cc.Node)
    spNode: cc.Node = null;
    @property(cc.Sprite)
    targetSp: cc.Sprite = null;
    @property(cc.Sprite)
    sp: cc.Sprite = null;
    @property(cc.Material)
    testMat: cc.Material = null;
    @property(cc.EffectAsset)
    gaussEffect: cc.EffectAsset = null;

    private _hMaterial: cc.Material = null;
    private _vMaterial: cc.Material = null;

    protected start(): void {
        // this.targetSp.spriteFrame = new cc.SpriteFrame();
        this._vMaterial = cc.Material.create(this.gaussEffect, 0);
        this._hMaterial = cc.Material.create(this.gaussEffect, 1);

        this._vMaterial.setProperty("u_texSize", cc.v2(1024, 1024));
        this._hMaterial.setProperty("u_texSize", cc.v2(1024, 1024));
    }

    onClick() {
        let srcTex = Utils.renderNodeToTexture(this.spNode);
        let desTex = new cc.Texture2D();
        Utils.renderTextureToTexture(srcTex, desTex, [this._vMaterial, this._hMaterial],5,1);
        this.targetSp.spriteFrame = new cc.SpriteFrame(desTex);
    }
}
